package com.technology.education.ui.teacher.author

import androidx.lifecycle.MutableLiveData
import com.technology.education.data.SpKeys
import com.technology.education.ext.postEventBus
import com.technology.education.ext.toast
import com.technology.education.network.apiService
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.ext.request

class AuthorViewModel : BaseViewModel() {
    var frontUrl = ""
    var backUrl = ""
    var authorUrl = ""
    var name = ""
    var idCard = ""
    val result = MutableLiveData<Boolean>()

    fun commit() {
        if (name.isEmpty()) {
            toast("请输入姓名")
            return
        }
        if (idCard.isEmpty()) {
            toast("请输入身份证号")
            return
        }
        if (frontUrl.isEmpty()) {
            toast("请选择身份证正面照")
            return
        }
        if (backUrl.isEmpty()) {
            toast("请选择身份证反面照")
            return
        }
        if (authorUrl.isEmpty()) {
            toast("请选择资质证书")
            return
        }
        request(
            {
                apiService.certTeacher(
                    hashMapOf(
                        "idCardImage1" to frontUrl, "idCardImage2" to
                                backUrl,
                        "idCardImage3" to authorUrl, "idCardNo" to idCard, "realName" to name
                    )
                )
            },
            success = {
                result.postValue(true)
                postEventBus(SpKeys.UPLOAD_AUTHOR, true)
            },
            error = { toast(it.errorMsg) }, isShowDialog = true
        )
    }


}